<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 将数组拆分成斐波那契序列 -->
    <script>
      var splitIntoFibonacci = function (S, start = 0, prev = [], r = []) {
        if (start === S.length) return r.push(...prev), (r.end = true)
        for (var i = start, cur = 0; i < S.length; i++) {
          cur = cur * 10 + (S[i] | 0)
          if (cur > Math.pow(2, 31) - 1) break
          if (prev.length === 2) {
            if (prev[0] + prev[1] === cur) {
              r.push(prev[0])
              if (splitIntoFibonacci(S, i + 1, [prev[1], cur], r) === true) return true
              r.pop()
            }
          } else if (i < S.length - 1) {
            prev.push(cur)
            if (splitIntoFibonacci(S, i + 1, prev.slice(), r) === true || cur === 0 || r.end) break
            prev.pop()
          }
        }
        return r
      }
      console.log(splitIntoFibonacci('1101111'))
    </script>
  </body>
</html>
